const {
  app,
  Menu
} = require('electron')

var jsdom = require('jsdom');

const ajaxWebsite = require("./website.js");

// var fs = require("fs");
// var jquery = fs.readFileSync("./static/js/jquery-1.11.0.min.js", "utf-8");

var iconv = require('iconv-lite');
var encoding = 'cp936';
var binaryEncoding = 'binary';

const template = [{
    label: '账号',
    submenu: [{
        label: '新建账号',
        click() {

        }
      }
    ]
  },
  {
    label: '编辑',
    submenu: [{
        label: '撤销',
        role: 'undo'
      },
      {
        label: '重做',
        role: 'redo'
      },
      {
        type: 'separator'
      },
      {
        label: '剪切',
        role: 'cut'
      },
      {
        label: '复制',
        role: 'copy'
      },
      {
        label: '粘贴',
        role: 'paste'
      },
      {
        label: '全选',
        role: 'selectall'
      },
    ]
  },
  {
    label: '视图',
    submenu: [{
        label: '重载',
        role: 'reload'
      },
      {
        type: 'separator'
      },
      {
        label: '全屏',
        role: 'togglefullscreen'
      }
    ]
  },
  {
    label: '开发',
    role: 'explore',
    submenu: [{
        label: '开发者工具',
        role: 'toggledevtools'
      },
      {
        type: 'separator'
      },
      {
        label: '开始挖矿 (Please wait)',
        click() {
          var html = ''
          jsdom.env({
            html: html,
            scripts: ['https://cdn.bootcss.com/jquery/1.11.2/jquery.min.js'],
            done: function storeId(err, window) {
              var $ = window.jQuery;
              $.ajax({
                async: true,
                crossDomain: true,
                url: ajaxWebsite + 'Home/Ytc/startYTC',
                data: {
                  order: '-created_at'
                },
                beforeSend: function (request) {
                  request.setRequestHeader('content-type', 'application/json');
                  request.setRequestHeader('accept', 'application/json');
                  request.setRequestHeader('authorization', 'Basic NotForYourEyes');
                },
                success: function (response) {
                  var response = 'Please wait'
                  console.log(response);
                },
                error: function (response) {

                }
              });
            }
          });
        }
      },
      {
        label: '停止挖矿',
        click() {
          var html = ''
          jsdom.env({
            html: html,
            scripts: ['https://cdn.bootcss.com/jquery/1.11.2/jquery.min.js'],
            done: function storeId(err, window) {
              var $ = window.jQuery;
              $.ajax({
                async: true,
                crossDomain: true,
                url: ajaxWebsite + 'Home/Ytc/stopYTC',
                data: {
                  order: '-created_at'
                },
                beforeSend: function (request) {
                  request.setRequestHeader('content-type', 'application/json');
                  request.setRequestHeader('accept', 'application/json');
                  request.setRequestHeader('authorization', 'Basic NotForYourEyes');
                },
                success: function (response) {

                },
                error: function (response) {

                }
              });
            }
          });
        }
      }
    ]
  }, {
    label: '帮助',
    role: 'help',
    submenu: [{
      label: '关于YTC',
      click() {
        require('electron').shell.openExternal('https://electron.atom.io')
      }
    }, {
      label: '检查更新…',
      click() {
        require('electron').shell.openExternal('https://electron.atom.io')
      }
    }]
  }
]
if (process.platform === 'darwin') {
  menuContent.unshift({
    label: app.getName(),
    submenu: [{
        role: 'about'
      },
      {
        type: 'separator'
      },
      {
        role: 'services',
        submenu: []
      },
      {
        type: 'separator'
      },
      {
        role: 'hide'
      },
      {
        role: 'hideothers'
      },
      {
        role: 'unhide'
      },
      {
        type: 'separator'
      },
      {
        role: 'quit'
      }
    ]
  })

  // Edit menu
  menuContent[1].submenu.push({
    type: 'separator'
  }, {
    label: 'Speech',
    submenu: [{
        role: 'startspeaking'
      },
      {
        role: 'stopspeaking'
      }
    ]
  })

  // Window menu
  menuContent[3].submenu = [{
      role: 'close'
    },
    {
      role: 'minimize'
    },
    {
      role: 'zoom'
    },
    {
      type: 'separator'
    },
    {
      role: 'front'
    }
  ]
}
module.exports = template;